package com.hxd.otc.module.coin_deal.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.coin_deal.bean.CoinDealRecoderBean;
import com.hxd.otc.module.coin_deal.contract.CoinDealRecoderContract;
import com.hxd.otc.module.coin_deal.model.CoinDealModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

import java.util.List;

/**
 * 包  名 :  com.hxd.otc.module.coin_deal.presenter
 * 类  名 :  CoinDealPresenter
 * 作  者 :  zjl
 * 时  间 :  2018/7/9 11:52
 * 描  述 :  ${币币交易Presenter}
 */
public class CoinDealRecordPresenter extends BasePresenter<CoinDealRecoderContract.View> implements CoinDealRecoderContract.Presenter {

    private final CoinDealModel mModel;

    public CoinDealRecordPresenter(CoinDealRecoderContract.View view) {
        super(view);
        mModel = CoinDealModel.getInstance();
    }

    @Override
    public void start() {

    }

    @Override
    public void loadData(int... category) {
        mModel.getCoinDealTransactionRecord(new BaseObserver<CoinDealRecoderBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull CoinDealRecoderBean coinDealRecoderBean) {

                doSetAdapter(coinDealRecoderBean.list);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.onError(errType);
                mView.showToast(errMessage);
                doShowNoMore();
            }
        }, mView.<BaseBean<CoinDealRecoderBean>>bindAutoDispose(), category);
    }

    @Override
    public void doSetAdapter(List<CoinDealRecoderBean.DataBean> data) {
        doShowNoMore();
        mView.onSetAdapter(data);
    }

    @Override
    public void doShowNoMore() {
        mView.onShowNoMore();
    }
}
